package com.elevator;

import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import data.setting;

@SuppressWarnings("serial")
public class adminUI extends JPanel {
	private JComboBox mLiftNumbox = null;
	private JComboBox mLayerNumbox = null;
	private JButton mManualRunning = null;
	private JButton mEmulatorRunning = null;
	public int mLiftNum = 1;
	public int mLayNum = 1;
	public adminUI()
	{
		this.setLayout(null);
		JLabel label = new JLabel("Lift Number:");
		this.add(label);
		label.setLocation(100, 50);
		label.setSize(100, 50);
		mLiftNumbox = new JComboBox();
		mLayerNumbox = new JComboBox();
		
		this.add(mLiftNumbox);
		this.add(mLayerNumbox);
		mLiftNumbox.setLocation(100, 110);
		mLiftNumbox.setSize(100, 30);
		mLayerNumbox.setLocation(250, 110);
		mLayerNumbox.setSize(100, 30);
		label = new JLabel("Layer Number:");
		this.add(label);
		label.setLocation(250, 50);
		label.setSize(100, 50);
		
		mLiftNumbox.addItem("1");
		mLiftNumbox.addItem("2");
		mLiftNumbox.addItem("3");
		mLiftNumbox.addItem("4");
		mLiftNumbox.addItem("5");
		mLiftNumbox.addItemListener(new  ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent e) {
				// TODO Auto-generated method stub
				if (e.getStateChange() == ItemEvent.SELECTED) 
				{
					mLiftNum = Integer.parseInt((String)e.getItem());
				}
			}
		});
		
		mLayerNumbox.addItem("Ground Floor");
		mLayerNumbox.addItem("1st Floor");
		mLayerNumbox.addItem("2nd Floor");
		mLayerNumbox.addItem("3rd Floor");
		mLayerNumbox.addItem("4th Floor");
		mLayerNumbox.addItem("5th Floor");
		mLayerNumbox.addItem("6th Floor");
		mLayerNumbox.addItem("7th Floor");
		mLayerNumbox.addItem("8th Floor");
		mLayerNumbox.addItem("9th Floor");
		mLayerNumbox.addItem("10th Floor");
		mLayerNumbox.addItemListener(new  ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent e) {
				// TODO Auto-generated method stub
				if (e.getStateChange() == ItemEvent.SELECTED) 
				{
					mLayNum = mLayerNumbox.getSelectedIndex() + 1;
				}
			}
		});
		mManualRunning = new JButton("manual running");
		mEmulatorRunning = new JButton("Simulation");
		
		this.add(mManualRunning);
		this.add(mEmulatorRunning);
		
		mManualRunning.setLocation(400, 50);
		mEmulatorRunning.setLocation(400, 100);
		mManualRunning.setSize(100, 40);
		mEmulatorRunning.setSize(100,40);
		
		mManualRunning.setMargin(new Insets(0, 0, 0, 0));
		mEmulatorRunning.setMargin(new Insets(0, 0, 0, 0));
	}
	
	public void setManualRunningBtnListener(ActionListener listener) {
		mManualRunning.addActionListener(listener);
	}
	
	public void setSimulationRunningBtnListener(ActionListener listener) {
		mEmulatorRunning.addActionListener(listener);
	}

    public void refeshView() {
        // TODO Auto-generated method stub
        mLiftNumbox.setSelectedItem(""+setting.sEvelatorCount);
        mLayerNumbox.setSelectedIndex(setting.sLayerCount-1);
    }
	
}
